import java.io.*;
import java.net.*;

public class MartiniPommitusServer{
	public static void main(String[] arg) throws Exception{
		ServerSocket ss = new ServerSocket(3003);
		Socket sc1 = ss.accept();
		PrintWriter vorku1 = new PrintWriter(sc1.getOutputStream(), true);
		BufferedReader br1 = new BufferedReader(new InputStreamReader(sc1.getInputStream()));
		vorku1.println("teretulemast, oota paarilist, joonista laevad paberile");
		
		Socket sc2 = ss.accept();
		PrintWriter vorku2 = new PrintWriter(sc2.getOutputStream(), true);
		BufferedReader br2 = new BufferedReader(new InputStreamReader(sc2.getInputStream()));
		vorku2.println("teretulemast, Joonista laevad paberile, Vastane alustab");
		vorku1.println("Paariline olemas, vajuta 'ENTER', kui laevad valmis ja oota kuni vastane ka valmis on");
		br1.readLine();
		vorku2.println("Paarilise laevad on valmis, kui sul ka siis vajuta 'ENTER'");
		br2.readLine();
		
		while(true){
			while(br1.ready()){br1.readLine();} //Tühjendab puhvri
			vorku1.println("Paku");
			String rida = br1.readLine();
			while(br2.ready()){br1.readLine();}
			vorku2.println("Pakuti "+ rida +". Vasta 'pihtas' voi paku ise");
			rida = br2.readLine();
			vorku1.println("Pakuti "+ rida);
		}
	}
}